package com.doyoulearn.websocket.service;

import cn.hutool.json.JSONUtil;
import com.doyoulearn.websocket.dto.WebAlarmSocketMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

@Service
public class WebAlarmSocketService {

    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    public void sendMessage(String userId) {WebAlarmSocketMessage result = new WebAlarmSocketMessage();

        result.setAlarm(userId);
        String destination = "/web/alarm/out/tenant" + userId;
        simpMessagingTemplate.convertAndSend(destination, JSONUtil.toJsonStr(result));
    }

}
